class Solution {
public:
  string convertToBase7(int num) {
    bool flag = false;
    string cnt;
    int x = 0;
    if(num < 0){
      flag = true;
      num = -num;
    }
    if (num >= 0 && num < 7) {
      cnt = to_string(num);
    }
    else if (num >= 7) {
      while (num >= 7) {
        int a = num % 7;
        num = num / 7;
        if(a != 0){
          cnt += to_string(a);
          continue;
        }
        else if(a == 0){
          cnt += "0";
          continue;
        }
      }
      cnt += to_string(num);
    }
    reverse(cnt.begin(), cnt.end());
    return flag ? "-" + cnt : cnt;
  }
};